/**************************************************************************/
/*                                                                        */
/* 跨越速运集团有限公司版权所有                                           */
/*                                                                        */
/* PROPRIETARY RIGHTS of KYE Company are involved in the                */
/* subject matter of this material. All manufacturing, reproduction, use, */
/* and sales rights pertaining to this subject matter are governed by the */
/* license agreement. The recipient of this software implicitly accepts   */
/* the terms of the license.                                              */
/* 本软件文档资料是跨越速运集团有限公司的资产，任何人士阅读和                   */
/* 使用本资料必须获得相应的书面授权，承担保密责任和接受相应的法律约束。                 */
/*                                                                        */
/**************************************************************************/

/**
 * <pre>  邮件发送
 * 作   者：liuyilong
 * 创建日期：2018-1-4
 * </pre>
 */
package com.kyexpress.common.hrinterview.provider.utils;

import ch.qos.logback.core.util.ContentTypeUtil;
import com.kyexpress.common.hrinterview.api.model.User;
import com.kyexpress.framework.model.UserInfo;
import com.kyexpress.framework.utils.Context;
import com.kyexpress.framework.utils.ContextUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class InterviewUtils {

   /* //性别
    private static int E_SEX_MAN = 10; //男
    private static int E_SEX_WOMAN = 20;//女
    //文化程序
    private static int E_SCHOOL_GZ = 10;//高中
    private static int E_SCHOOL_ZK = 20;//专科
    private static int E_SCHOOL_BK = 30;//本科
    private static int E_SCHOOL_SS = 40;//硕士master
    private static int E_SCHOOL_BS = 50;//博士
    //是否需要背调
    private static  int E_BT_YES = 10;//是
    private static  int E_BT_NO = 20;//否
    //状态
    private static  int E_STATUS_DMS = 10;//待面试
    private static  int E_STATUS_WDD = 20;//未到达
    private static  int E_STATUS_TG = 30;//面试通过
    private static  int E_STATUS_WTG = 40;//面试未通过
    private static  int E_STATUS_DT = 50;//待定
    private static  int E_STATUS_RZZ = 60;//入职中
    private static  int E_STATUS_RZWC = 70;//入职完成
    //是否已发offer
    private static  int E_OFFER_NO = 10;//未发
    private static  int E_OFFER_ = 20;//已发*/

    //保存登录的id和token，用户验证登录
    public static Map<String,String> xuidMap = new HashMap<String,String>();
    //保存登录信息
    public static Map<String,User> loginUserMap = new HashMap<String,User>();

    /**
     * 判断是否登录
     * @return
     */
    public static boolean isLogin(){
        Context context = ContextUtils.get();
        String idToken = context.getUser().getId();
        if(idToken == null || idToken.trim().length() == 0){
            return false;
        }
        if(idToken == null || idToken.trim().length() < 20){
            return false;
        }
        String id = idToken.substring(0,18);
        String token = idToken.substring(18);
        if(id == null || id.trim().length() == 0){
            return false;
        }
        if(token == null || token.trim().length() == 0){
            return false;
        }
        String memXuid = xuidMap.get(id);
        if(memXuid == null || memXuid.trim().length() == 0){
            return false;
        }
        if(!memXuid.equals(id+token)){
            return false;
        }
        UserInfo userInfo = context.getUser();
        userInfo.setId(id);
        context.setUser(userInfo);
        return true;
    }

    /**
     *  获取登录信息
     * @param id
     * @return
     */
    public static User getLoginUser(String id){
        return loginUserMap.get(id);
    }
}
